//股东股权
function resultGdgqs(result){
    var jsonData=Ext.decode(result.responseText);
    var array=null;
    var finalData=null;
    for(var key in jsonData){
           if(key=="gdgqdatas"){
             array=jsonData[key];
           }else if(key=="finalDatas"){
             finalData=jsonData[key]
           }
     }
  
    var html='<table width="1000" border="0" cellspacing="2" cellpadding="2">'+
    '<tr>'+
    '<td><table width="100%" border="0" cellspacing="2" cellpadding="2" >'+
    '<tr><td height="55" bordercolor="#000000" align="center" style="font-size:22px;">'+
    '<br/><b>修改后企业股东以及股权结构</b> <br/> <br/>'+
    '</td></tr>'+
    '</table></td>'+
    '</tr>'+
    '<tr>'+
    '<td>'+
    '<table id="t_ssylb" width="100%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="2" class="tpl_list_ui" id="myTable">'+
    '<tbody id="myBody">'+
    '<tr>'+
    '<td width="5%" height="0" ></td>'+
    '<td width="10%"></td>'+
    '<td width="20%"></td>'+
    '</tr>'+
    '<TR d="myTr0" align="center">'+
    '<td height="25" align="center" bordercolor="#000000">序号</td>'+
    '<td heght="25" align="center" colspan="2" bordercolor="#000000">企业股东名称</td>'+
    '<td height="25" align="center" colspan="2" bordercolor="#000000">股份所占比例</td>'+
    '<td height="25" align="center" bordercolor="#000000">操作</td>'+
    '</tr>';
    for(var i=0;i<array.length;i++){
        html+="<tr height='25' align='center'><td>"+(i+1)+
        "</td><td colspan='2'>"+array[i].qygdmc+
        "</td><td colspan='2'>"+array[i].gfszbl+
        "</td>"+
        "<td><input type='button' value='编辑'  onclick='toGdgq("+array[i].id+")'> <input type='button' value='删除'  onclick='deletegdgq("+array[i].id+")'></td></tr>";
   
        }
        html+='</tbody></table></td></tr>'+
        '<tr><td colspan="5" bordercolor="#000000"><input type="button" value="添加一行" onclick="tosaveGdgq()"></td>'+
        '</tr>'+
        '</table>';
        document.getElementById("gdgqview").innerHTML=html;
  
    var finalhtml='<table width="1000" border="0" cellspacing="2" cellpadding="2">'+
               '<tr>'+
                '<td><table width="100%" border="0" cellspacing="2" cellpadding="2" >'+
                '<tr><td height="55" bordercolor="#000000" align="center" style="font-size:22px;">'+
                '<br/><b>原企业股东以及股权结构</b> <br/> <br/>'+
                '</td></tr>'+
                '</table></td>'+
                '</tr>'+
                '<tr>'+
                '<td>'+
                '<table id="t_ssylb" width="100%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="2" class="tpl_list_ui" id="myTable">'+
                '<tbody id="myBody">'+
                '<tr>'+
                '<td width="5%" height="0" ></td>'+
                '<td width="10%"></td>'+
                '<td width="20%"></td>'+
                '</tr>'+
                '<TR d="myTr0" align="center">'+
                '<td height="25" align="center" bordercolor="#000000">序号</td>'+
                '<td heght="25" align="center" colspan="2" bordercolor="#000000">企业股东名称</td>'+
                '<td height="25" align="center" colspan="2" bordercolor="#000000">股份所占比例</td>'+
                '</tr>';
                 for(var k=0;k<finalData.length;k++){
                        finalhtml+="<tr height='25' align='center'><td>"+(k+1)+
                        "</td><td colspan='2'>"+finalData[k].qygdmc+
                        "</td><td colspan='2'>"+finalData[k].gfszbl+
                        "</td>"+"</tr>";
                        }
                        finalhtml+='</tbody></table></td></tr>'+
                        '</table>';
                  document.getElementById("fianlgdgqview").innerHTML=finalhtml;

}


//编辑股东
function toGdgq(gdid){
    var id=document.getElementById("id").value;
      Ext.Ajax.request({
       url: '${ctx}/yw-rq-qyjyxkgd!getGdgq.action',
       success:toEditeGdgq,
       failure:faultHandler,
       params: {id:id,gdid:gdid}
      });
  }


//显示添加股东股权
function tosaveGdgq(){
       _win=new Ext.Window({
        title:'新增股东以及股权结构',
        width:600,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td width:200 align=right>企业股东名称:</td><td><input type="text" name="qygdmc" id="qygdmc"></td>'+
        '<tr><td width:200 align=right>股份所占比例:</td><td><input type="text" name="gfszbl" id="gfszbl"></td>'+
        '</tr>'+
        '</table>',
        buttons:[{text:'保 存',handler:saveGdGq},{text:'取 消',handler:function(){
            _win.hide();
        }}]
    });
    _win.show();

}

//编辑股东股权
function toEditeGdgq(result){
var array = Ext.decode(result.responseText);
 _editwin=new Ext.Window({
        title:'编辑股东股权',
        width:400,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td colspan="2"><input type="hidden" name="gdId" id="gdId" value="'+array.id+'">'+
        '<input type="hidden" name="qyid" id="qyid" value="'+array.qyid+'">'+
         '<input type="hidden" name="zdlb" id="zdlb" value="'+array.zdlb+'">'+
        '<input type="hidden" name="ssylbid" id="ssylbid" value="'+array.ssylbid+'"></td>'+
        '<tr><td width:200 align=right>企业股东名称:</td><td><input type="text" name="qygdmc" id="qygdmc" value="'+array.qygdmc+'"></td>'+
        '<tr><td width:200 align=right>股份所占比例:</td><td><input type="text" name="gfszbl" id="gfszbl" value="'+array.gfszbl+'"></td>'+
          '</tr>'+
        '</table>',
        buttons:[{text:'保 存',handler:saveGdGq},{text:'取 消',handler:function(){
            _editwin.hide();
        }}]
    }).show();
}


//保存股东股权
function  saveGdGq(){

    var qyid=$('#qyid').val();
    var acceptNo=$('#acceptNo').val();
    var userName=$('#userName').val();
    var qygdmc = dwr.util.getValue('qygdmc');
    var gfszbl = dwr.util.getValue('gfszbl');
    var gdId = dwr.util.getValue('gdId');
    var uploadDate = new Date();
    var  id=$("#id").val();
    var obj;    
     if(gdId==null||typeof(gdId) == "undefined"||gdId==""){
         obj ={
          qyid:qyid,
          acceptNo:acceptNo,
          userName:userName,
          qygdmc:qygdmc,
          gfszbl:gfszbl,
          uploadDate:uploadDate
          };    
        }else{
         obj ={
           qyid:qyid,
          acceptNo:acceptNo,
          userName:userName,
          qygdmc:qygdmc,
          gfszbl:gfszbl,
          uploadDate:uploadDate,
          id:id,
          gdId:gdId
          };
        }
       var params=Ext.encode(obj);
       Ext.Ajax.request({
           url: '${ctx}/yw-rq-qyjyxkgd!saveGdGq.action',
           success:showGdgqs,
           failure:faultHandler,
           params:obj
       });
}

//跳到股东列表
function showGdgqs(){
        if(_win!=null)
           _win.close();
         if(_editwin!=null)
         _editwin.close();
  var  id=$("#id").val();
     Ext.Ajax.request({
       url: '${ctx}/yw-rq-qyjyxkgd!getgdgqs.action',
       success:resultGdgqs,
       failure:faultHandler,
       params: { id: id}
   });  
}

//删除一行
function deletegdgq(gdId){
     var id=document.getElementById("id").value;
    Ext.MessageBox.confirm('警告!','您确定要删除吗?',function(btn){
    if (btn == 'yes'){
      Ext.Ajax.request({
        url: '${ctx}/yw-rq-qyjyxkgd!deletegdgq.action',
       success:showGdgqs,
       failure:faultHandler,
       params: {gdId:gdId,
                id:id}
        });
       }
    });
}


//燃气设施开始--------------------------------------------------



function updateQxssDj(id){
     var qyxxForm=serializeForm("rqqxssdj");
    var action="${ctx}/yw-rq-qyjyxk-rqss!doUpdate.action";
    alert(ywPanel);
    doCommit(action,qyxxForm,rqqxssPanel);
}

function doCommit(url,params,panel){
       wait.show();
       Ext.Ajax.request({
       url: url,
       dataType:"json",
       params: params,
       success:function(response){
        wait.hide();
         var result=response.responseText;
         if(result=="success"){
              Ext.Msg.alert("提示","操作成功",function(){
                window.location.reload();
                 ywPanel.setActiveTab(panel);
            });
         }else{
            Ext.Msg.alert("提示","操作失败");
              return;    
         }
    },failure: function() {
        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
         wait.hide();
     } 
    
    });
}

function opentWindow(url,width,height,name,resizable){
    var left, top;
    left = parseInt((screen.width - width)/2);
    top  = parseInt((screen.height - height)/2);
    var newWindown= window.open(url, "", "top="+top+",left="+left+",width="+width+",height="+height+",location=no,scrollbars = no,resizable=yes");
    //返回当前窗口
    return newWindown;
}



function changValue(url){
     Ext.Ajax.request({
       url: url,
       params:"",
       success:function(response){
          var result=response.responseText;
          var jsonData =eval('('+result+')');
	         for(var key in jsonData){
                  if(jsonData[key] == 'null' || jsonData[key] == null){ 
                      jsonData[key] = '';
                  }
                  if(document.getElementById(key)){
	                  if(key=="address"){
	                       document.getElementById(key).value=jsonData[key];
	                  }else if(key=="dzyx"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="post"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="gszcdjh"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="ywlxr"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="ywlxrtel"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="email"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="cz"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="qywz"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="fddbr"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="fddbrZw"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="fddbrZc"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="zyfzr"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="zyfzrZw"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="zyfzrZc"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="aqfzr"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="aqfzrZw"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="aqfzrZc"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="jsfzr"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="jsfzrZw"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="jsfzrZc"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="qyzczb"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="jyfw"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="gqqy"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="fwdh"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="qxdh"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="qyjj"){
	                        document.getElementById(key).value=jsonData[key];
	                  }else if(key=="clsj"){
	                       var dateObj=jsonData[key];
	                       if(dateObj!="" && dateObj!=""){
		                       var date=fromatDate(dateObj);
		                       document.getElementById(key).value=date;
	                       }
	                 }else if(key=="qylx"){
	                       changeqylxValue("qylx",jsonData[key]);
	                 }
                 }
               }
           }
  });
}


function changeqylxValue(name,val){
    var objs=document.getElementsByName(""+name);
    for(j=0;j<objs.length;j++){
        if(objs[j].value==val){
        objs[j].checked=true; 
            break; 
        }
    
    }
}
function fromatDate(dateObj){
	var months=dateObj.month+1;
	var years=parseInt(dateObj.year+1900);
	var dates=parseInt(dateObj.date);
	 if(months<10){
	    months="0"+months;
	 }
	  if(dates<10){
	    dates="0"+dates;
	 }
	 
	var ndate = years+"年"+months+"月"+dates+"日";
    return ndate;
}


function checkNum(obj){
    obj.value = obj.value.replace(/\.$/g,""); 
}


 function clearNoNum(event,obj){ 
     //响应鼠标事件，允许左右方向键移动 
     event = window.event||event; 
     if(event.keyCode == 37 | event.keyCode == 39){ 
         return; 
     } 
     //先把非数字的都替换掉，除了数字和. 
     obj.value = obj.value.replace(/[^\d.]/g,""); 
     //必须保证第一个为数字而不是. 
     obj.value = obj.value.replace(/^\./g,""); 
     //保证只有出现一个.而没有多个. 
     obj.value = obj.value.replace(/\.{2,}/g,"."); 
     //保证.只出现一次，而不能出现两次以上 
     obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
 } 
 
 
 function changeTogether(){
    var setsslb=document.getElementById("sslb");
	var selectedValue = setsslb.value;
	$("#sskh").children("span").each(function(){
		$(this).children().clone().replaceAll($(this));
	});
	if(parseInt(selectedValue) != 0){
		if(selectedValue=="供应站" || selectedValue=="储配站" || selectedValue=="汽车加气站"){
			$("#sskh").children("option[parentid!='" + selectedValue + "'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}else if(selectedValue=="灌装站"){
			$("#sskh").children("option[parentid!='储配站'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}else if(selectedValue=="门站"){
			$("#sskh").children("option[parentid!='门站'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}else if(selectedValue=="LNG气化站"){
			$("#sskh").children("option[parentid!='LNG气化站'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}else if(selectedValue=="人工煤气储配站"){
			$("#sskh").children("option[parentid!='人工煤气储配站'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}else{
			$("#sskh").children("option[parentid!='others'][value!='0']").each(function(){
				$(this).wrap("<span style='display:none'></span>");
			});
		}
	}
}


//设施一览表的上传材料显示
function showTitle(ctx,fjPath,fjType,fjName){
	var html="";
	if(fjPath != ""){
		if(fjPath.indexOf(",")>=0){
			var path =  fjPath.split(",");
			var type = fjType.split(",");
			var name = fjName.split(",");
			for(var i =0;i<path.length;i++){	
				var fjUrl = ctx+path[i];
			    var fjUrl2 = "'"+fjUrl+"'";
			 
			     html += '<a href="javascript:openFile('+fjUrl2+');" title="'+name[i]+'"><img src="'+ctx+'/resources/images/fileType/'+type[i]+'.gif" onerror="nofound();" border="0" class="img_16x16"/></a>&nbsp;';
			    if(i > 0 && i%4 == 0){
			    	html +="<br/>";
			    }
			}
			return html;
		}else{
				var fjUrl = ctx+fjPath;
			    var fjUrl2 = "'"+fjUrl+"'";
			    var html = '<a href="javascript:openFile('+fjUrl2+');" title="'+fjName+'"><img src="'+ctx+'/resources/images/fileType/'+fjType+'.gif" onerror="nofound();" border="0" class="img_16x16"/></a>&nbsp;';
			    return html;
		}
	}else{
		return "";
	}
}


function openFile(url) {
		window.open(url);
}
